package reflect;

/**
 * JDK1.5之后推出了一个特性:变长参数
 *
 */
public class ArgsDemo {
    public static void main(String[] args) {
        doSome();
        doSome("1");
        doSome("1","2");
        doSome("1","2","3");
        doSome("1","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3");
//        向变长参传入实参时，会被编译器改为数组
//        doSome(new String[]{});
//        doSome(new String[]{"1"});
//        doSome(new String[]{"1","2"});
//        doSome(new String[]{"1","2","3"});
//        doSome(new String[]{"1","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3","2","3"});
    }

    /**
     *  变长参是编译器认可的，编译后会将变长参数改为数组类型
     *
     *  变长参数有一个要求:该参数只能是方法的最后一个参数
     * @param arg
     */
    public static void doSome(String... arg){
//    public static void doSome(String[] arg){
        System.out.println(arg.length);
    }

}







